package ${apiPackage};

import org.springframework.stereotype.Service;
import ${servicePackage}.${serviceName};
import ${entityPackage}.${entityName};
import ${modelPackage}.${modelName};
<#if enableLombok>
import lombok.RequiredArgsConstructor;
</#if>

/**
* ${tableComment} API
* @author ${author}
* @since ${date}
*/
@Service
<#if enableLombok>
@RequiredArgsConstructor
</#if>
public class ${apiName}{

    private final ${serviceName} ${serviceName?uncap_first};

<#if !enableLombok>
    public ${apiName}(${serviceName} ${serviceName?uncap_first}){
        this.${serviceName?uncap_first} = ${serviceName?uncap_first};
    }

</#if>
    /**
     * 插入新数据
     * @author ${author}
     * @since ${date}
     * @param model:
    */
    public void insert(${modelName} model){
        ${entityName} entity = ${entityName}.convert(model,new ${entityName}());
<#if enableMyBatisPlus>
        ${serviceName?uncap_first}.save(entity);
<#else>
        ${serviceName?uncap_first}.insert(entity);
</#if>
    }

<#if primaryColumn?? && (primaryColumn?size == 1)>
    /**
     * 根据ID删除记录
     * @author ${author}
     * @since ${date}
     * @param id:
    */
    public void deleteById(${primaryColumn[0].javaType} id){
    <#if enableMyBatisPlus>
        ${serviceName?uncap_first}.removeById(id);
    <#else>
        ${serviceName?uncap_first}.deleteById(id);
    </#if>
    }

    /**
     * 根据ID选择性更新
     * @author ${author}
     * @since ${date}
     * @param model:
    */
    public void updateSelectiveById(${modelName} model){
        ${entityName} entity = ${entityName}.convert(model,new ${entityName}());
        ${serviceName?uncap_first}.updateSelectiveById(entity);
    }

    /**
     * 根据ID查询记录
     * @author ${author}
     * @since ${date}
     * @param id:
     * @return ${modelPackage}.${modelName}
    */
    public ${modelName} selectById(${primaryColumn[0].javaType} id){
    <#if enableMyBatisPlus>
        ${entityName} entity = ${serviceName?uncap_first}.getById(id);
    <#else>
        ${entityName} entity = ${serviceName?uncap_first}.selectById(id);
    </#if>
        return ${entityName}.convert(entity,new ${modelName}());
    }

</#if>

}

